package com.aistar.service.job.impl;

import com.aistar.mapper.CompanyMapper;
import com.aistar.mapper.RecruitmentMapper;
import com.aistar.model.dto.job.RecruitmentAndCompanyDTO;
import com.aistar.model.entity.Company;
import com.aistar.service.job.ICompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CompanyServiceImpl implements ICompanyService {
    @Autowired
    private RecruitmentMapper recruitmentMapper;
    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public List<Company> search() {
        return companyMapper.find();
    }

    @Override
    public Company findById(Integer id) {
        return companyMapper.findById(id);
    }

    @Override
    public List<Company> searchName(String name, String financing, String num,String province,String city,String district) {

        return companyMapper.findByName(name, financing, num,province,city,district);
    }

    @Override
    public PageInfo<Company> cutPage(String name,String province,String city,String district, String financing, String num, Integer page, Integer limit) {
        List<RecruitmentAndCompanyDTO> recruitmentAndCompanyDTOList = new ArrayList<>();
        PageHelper.startPage(page, limit);
        List<Company> companyList = companyMapper.findByName(name, financing, num, province, city,district);
        PageInfo<Company> pageInfo = new PageInfo<>(companyList);

//        for (Company recruitment : pageInfo.getList()) {
//            RecruitmentAndCompanyDTO recruitmentAndCompanyDTO = new RecruitmentAndCompanyDTO();
//            recruitmentAndCompanyDTO.setRecruitment(recruitment);
//            Company company =companyMapper.findById(recruitment.getCompanyId());
//            recruitmentAndCompanyDTO.setCompany(company);
//            recruitmentAndCompanyDTOList.add(recruitmentAndCompanyDTO);
//        }
        return pageInfo;
    }
}
